﻿using JUtil;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using JUtil.ResourceManagement;
using System.Data.SqlClient;

public partial class announcement : System.Web.UI.Page
{
    public bool USING_OLE_DB = true;
    public bool TEST_DBUTILS = false;

#if true
    private IDatabase Db
    {
        get
        {

            string connectionString = @"Data Source=tppddb;User ID=tpdbuser;Password=tpdbuser;";
            DbProvider mode = DbProvider.Oracle;

            if (USING_OLE_DB)
            {
                connectionString = @"Provider =OraOLEDB.Oracle; Data Source =tppddb; User Id =tpdbuser; Password =tpdbuser; OLEDB.NET =True;";
                mode = DbProvider.OleDb;
            }

            IDatabase db = new XDatabase(mode, connectionString);

            return db;
        }
    }
#else
    private IDatabase Db
    {
        get
        {

            string connectionString = @"Data Source=JELLY\SQLEXPRESS;Password=sapass;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;";
            DbProvider mode = DbProvider.SqlServer;

            if (USING_OLE_DB)
            {
                connectionString = @"Provider=SQLOLEDB.1;Password=sapass;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=JELLY\SQLEXPRESS";
                mode = DbProvider.OleDb;
            }

            IDatabase db = new XDatabase(mode, connectionString);

            return db;
        }
    }
#endif

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (TEST_DBUTILS)
        //    TestDbUtils();
        //else
            BindData();

        TestDbUtils();
    }
    private void TestDbUtils()
    {
        DbUtils util = new DbUtils(Db);

        //foreach (string s in util.GetDatabases())
        //    Log.D(s);

        Log.W("");

        foreach (string s in util.GetTables())
            Log.D(s);

        Log.W("");

        //foreach (string s in util.GetViews())
        //    Log.D(s);
    }
    private DataTable CreateDataSource()
    {
        string sql = SqlFile.GetSQL("CreateDataSource");

        //DataTable dt = Db.GetSchema("Tables");
        DataTable dt = Db.GetSchema("Tables");

        return dt;
    }

    

    

    void BindData()
    {
        grv.DataSource = DataSource;
        grv.DataBind();
    }
    
    private DataTable DataSource
    {
        get
        {
            object o = Application["DataSource"];

            //if (o == null)
            {
                o = CreateDataSource();
                //Application.Add("DataSource", o);
            }
            return o as DataTable;
        }
    }

    
    
}
